#include<bits/stdc++.h>
using namespace std;
int n,x,s,sum;
int a[10000010],b[10000010];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>n;
    while(n--)
    {
        sum=0;
        cin>>x;
        for(int i=1;i<=x;i++)
        {
            cin>>a[i];
            b[i]=a[i];
        }
        if(x%2==0)
        {
            a[x]=0;
        }
        else
        {
            a[x]=1;
        }
        a[1]=1;
        for(int i=2;i<x-1;i+=3)
        {
            a[i]=1;
            a[i+1]=0;
            a[i+2]=1;

        }
        for(int i=1;i<=x;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(a[i]==a[j]&&b[i]==b[j])
                {
                    sum+=(b[i]/2);
                }
            }
        }
        cout<<sum-4;
    }
    return 0;
}
